#include <iostream>
#include <algorithm>
#include<math.h>
using namespace std;
float computeTriangleArea(float a, float b, float c) {
    float p = (a + b + c) / 2.0f;
    return std::sqrt(p * (p - a) * (p - b) * (p - c));
}

float findMaxPerimeterAndMaxArea(int m, float* lengths, float& maxPerimeter, float& maxArea) {
    maxPerimeter = maxArea = 0.0f;

    std::sort(lengths, lengths + m, std::greater<float>());

    for (int i = 0; i < m - 2; i++) {
        if (lengths[i] < lengths[i + 1] + lengths[i + 2]) {
            float a = lengths[i];
            float b = lengths[i + 1];
            float c = lengths[i + 2];
            maxPerimeter = a + b + c;
            maxArea = computeTriangleArea(a, b, c);
            return maxPerimeter;
        }
    }

    return 0.0f;
}

int main() {
    int m;
    std::cout << "请输入木棍的数目m: ";
    std::cin >> m;

    float* lengths = new float[m];
    std::cout << "请输入" << m << "根木棍长度: ";
    for (int i = 0; i < m; i++) {
        std::cin >> lengths[i];
    }

    float maxPerimeter, maxArea;
    float result = findMaxPerimeterAndMaxArea(m, lengths, maxPerimeter, maxArea);
    if (result == 0.0f) {
        std::cout << "无法构成三角形" << std::endl;
    } else {
        std::cout << "构成的最大三角形周长为: " << maxPerimeter << std::endl;
        std::cout << "构成的最大三角形面积为: " << maxArea << std::endl;
    }

    delete[] lengths;

    return 0;
}